package com.codervibe.web.controller;


import com.codervibe.model.User;
import com.codervibe.server.service.UserService;
import com.codervibe.web.common.response.R;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;



@RestController
@RequestMapping("/user")
public class UserController {
    Logger logger = LoggerFactory.getLogger(UserController.class);

    @Resource
    private UserService userService;


    @GetMapping("/list")
    public R list() {
        logger.info("用户列表 ：" + userService.selectUserAll().toString());
        return R.ok().data("userItems", userService.selectUserAll()).message("用户列表");
    }

    @GetMapping("/addList")
    public R addList() {
        List<User> userList = new ArrayList<>();
        userList.add(new User(1, "孙榕汕", "hhoM1Lk8", "94df@f4m2.com.cn", new Date(), "1"));
        userList.add(new User(2, "孔雄霖", "L7V2B5Bz", "461b@91y35u.xyz", new Date(), "3"));
        userList.add(new User(3, "张伟洋", "IkKjkImc", "6959@687kyp.com", new Date(), "2"));
        userList.add(new User(4, "魏语晨", "26G17x8B", "fa57@196bmfgq.com.cn", new Date(), "3"));
        userList.add(new User(6, "许添池", "g4&QM6w9", "88ac@o23wg.com", new Date(), "3"));
        userList.add(new User(7, "贺易轩", "88b15Vrb", "1cab@1e0179a.vip", new Date(), "4"));
        userList.add(new User(8, "谭诗悦", "4VoO4CgH", "447c@yw17my.site", new Date(), "4"));
        userList.add(new User(9, "丁亦菲", "3*7q8318", "9667@u82vtmfs.com.cn", new Date(), "4"));

        Map<String, Object> map = new HashMap<>();
        try {
            userService.addList(userList);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error();
        }
        return R.ok();
    }

    @GetMapping("/queryByid")
    public R queryUserByid(@RequestParam("id") String id) {
        logger.info("根据ID 查询信息");
        return R.ok().data("User", userService.selectUserByid(id)).message("用户信息");
    }


}
